#!/bin/bash

if [[ $(id -u) != 0 ]]; then
    echo "Please run as root or use sudo"
    exit 1
fi

set -e

# Debian 12
PKGS="${PKGS} procps util-linux linux-perf"
# PKGS="${PKGS} libtraceevent-dev"
PKGS="${PKGS} trace-cmd"
PKGS="${PKGS} bpftrace python3-bpfcc"

# for bpf script include
# root@localhost:~# bpftrace bpf-perf-tools-book/originals/Ch06_CPUs/offcputime.bt
# definitions.h:2:10: fatal error: 'linux/sched.h' file not found
PKGS="${PKGS} linux-headers-$(uname -r)"
# apt-get install -y bpfcc-tools

# linux-image-6.1.0-31-arm64-dbg: Need to get 799 MB of archives
# After this operation, 5188 MB of additional disk space will be used
PKGS="${PKGS} linux-image-$(uname -r)-dbg"
PKGS="${PKGS} crash"
PKGS="${PKGS} kdump-tools" # select Yes to enable service

# PKGS="${PKGS} linux-tools-common"
# PKGS="${PKGS} ddd"
# PKGS="${PKGS} kernelshark"
## bpftrace libbpfcc libclang-cpp14 libclang1-14
# PKGS="${PKGS} libopencsd1"

SUCCESSED=""
FAILED=""

for pkg in ${PKGS}; do
    echo "Installing ${pkg}"
    apt-get install -y ${pkg} \
        && SUCCESSED="${SUCCESSED} ${pkg}" \
        || FAILED="${FAILED} ${pkg}"
done

echo "SUCCESSED: " ${SUCCESSED}
echo "FAILED: " ${FAILED}

